package action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import model.News;
import service.DocManageService;
import service.UserService;

import com.opensymphony.xwork2.ActionSupport;

public class DocManageAction extends ActionSupport{
	private DocManageService docManageService;
	private News news;
	private String newsTitle;
	private String newsReporter;
	private String newsContent;
	private int newsMaxNum = 20;
	private int pageNum;
    private List newsList;
    
	

	public String execute() {
		this.setNews(new News());
		this.news.setNewsContent(newsContent);
		this.news.setNewsReporter(newsReporter);
		this.news.setNewsTitle(newsTitle);
		Date date = new Date();
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String time = df1.format(date);
		Timestamp CreateDate = Timestamp.valueOf(time);
		this.news.setSubmitTime(CreateDate);
		docManageService.saveDoc(this.news);
		return SUCCESS;
	}

	public String findNewsListByPage(){
		String[] propertys = {"id","newsTitle","submitTime"};
		newsList = docManageService.findPropertysForPage(propertys, pageNum, newsMaxNum, "submitTime");
		return SUCCESS;
	}
	
	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public News getNews() {
		return news;
	}

	public String getNewsTitle() {
		return newsTitle;
	}

	public void setNewsTitle(String newsTitle) {
		this.newsTitle = newsTitle;
	}

	public String getNewsReporter() {
		return newsReporter;
	}

	public void setNewsReporter(String newsReporter) {
		this.newsReporter = newsReporter;
	}

	public String getNewsContent() {
		return newsContent;
	}

	public void setNewsContent(String newsContent) {
		this.newsContent = newsContent;
	}
	public List getNewsList() {
		return newsList;
	}

	public void setNewsList(List newsList) {
		this.newsList = newsList;
	}

	public void setNews(News news) {
		this.news = news;
	}
	public void setDocManageService(DocManageService docManageService) {
		this.docManageService = docManageService;
	}
}
